package com.songcha.library_business.viewmodel

import android.app.Application
import com.alibaba.android.arouter.launcher.ARouter
import com.songcha.library_base.interfaces.IApiResult
import com.songcha.library_base.mvvm.base.BaseRepository
import com.songcha.library_base.mvvm.base.BaseViewModel
import com.songcha.library_base.mvvm.exception.LoginTokenInvalidException
import com.songcha.library_business.api.ApiManager
import com.songcha.library_business.bean.user.UserInfoBean
import com.songcha.library_business.proxy.userinfo.UserInfoManager

open class BaseErrorViewModel<R: BaseRepository>(app: Application):BaseViewModel<R>(app) {
    init {
        apiErrorListener = object :IOnApiErrorListener{
            override fun onApiError(e: Throwable) {
                if(e is LoginTokenInvalidException){
                    UserInfoManager.clearLogin()
                    //getUserInfo()
                    /*ARouter.getInstance().build("/task/DailyTaskController").navigation()?.let {
                        (it as ILogoutProvider).onLogout()
                    }*/
                }
            }
        }
    }

    /*private fun getUserInfo(){
        handleApiDataObserver(ApiManager.api.getUserInfo(),object : IApiResult<UserInfoBean> {
            override fun onSuccess(bean: UserInfoBean) {
                UserInfoManager.saveUserInfo(bean.data)
            }

            override fun onError(e: Throwable) {
            }
        })

    }*/


}